package com.kaisa.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kaisa.activity.R;
import com.kaisa.activity.bean.EnjoyHoliday;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by 123 on 2015/12/17.
 */
public class EnjoyHolidayAdapter extends AppBaseAdapter<EnjoyHoliday.DataEntity> {
    public EnjoyHolidayAdapter(List<EnjoyHoliday.DataEntity> list, Context context) {
        super(list, context);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        EnjoyViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_hot_sell, null);
            holder = new EnjoyViewHolder(convertView);
        } else {
            holder = (EnjoyViewHolder) convertView.getTag();
        }
        x.image().bind(holder.webView, list.get(position).getImage());
        holder.titleTextView.setText(list.get(position).getTitle());
        holder.moneyTextView.setText("¥" + list.get(position).getPrice());
        List<String>tags = list.get(position).getTags();
        holder.linearLayout.removeAllViews();
        for (int i = 0; i <2; i++) {
            TextView tv = new TextView(context);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            tv.setLayoutParams(params);
            tv.setText(tags.get(i));
            tv.setPadding(10,0,10,0);
            tv.setTextColor(context.getResources().getColor(R.color.blackishgreen));
            tv.setBackground(context.getResources().getDrawable(R.drawable.bg_sell_flag));
            holder.linearLayout.addView(tv);
        }
        return convertView;
    }

    public static class EnjoyViewHolder extends BaseViewHolder {
        @ViewInject(R.id.item_sell_img)
        private ImageView webView;
        @ViewInject(R.id.item_sell_title)
        private TextView titleTextView;
        @ViewInject(R.id.item_sell_money)
        private TextView moneyTextView;
        @ViewInject(R.id.item_ll_flag)
        private LinearLayout linearLayout;

        public EnjoyViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this, convertView);
        }
    }
}
